package generic;

import java.util.ArrayList;

public class Generic01{
    public static void main(String[] args) {
        ArrayList ay = new ArrayList<>();
        ay.add(new Dog("wangcai", 10));
        ay.add(new Dog("facai", 1));
        ay.add(new Dog("xiaohuang", 5));
        ay.add(new Cat("jiafei", 3));
        for(Object o:ay){
            Dog dog=(Dog)o;
            System.out.println(dog.getName()+" "+dog.getAge() );
        }
    }
}
class Dog{
    private String name;
    private int age;
    public Dog(String name,int age){
        this.name=name;
        this.age=age;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}
class Cat{
    private String name;
    private int age;
    public Cat(String name,int age){
        this.name=name;
        this.age=age;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}